package com.camartsApp.controller;

import com.camartsApp.common.ResultVO;
import com.camartsApp.dto.CommentCreateDTO;
import com.camartsApp.dto.PostDTO;
import com.camartsApp.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/post")
public class PostController {

    @Autowired
    private PostService postService;

    @GetMapping("/{imageId}")
    public ResultVO getPostByImageId(@PathVariable("imageId") Long imageId) {
        PostDTO postDTO = postService.getPostByImageId(imageId);
        if (postDTO != null) {
            return new ResultVO(ResultVO.SUCCESS, "Post retrieved successfully", postDTO);
        } else {
            return new ResultVO(ResultVO.FAIL, "Post not found", null);
        }
    }

    /**
     * 发布新评论
     */
    @PostMapping("/api/comment")
    public ResultVO addComment(@RequestBody CommentCreateDTO commentCreateDTO) {
        boolean success = postService.addComment(commentCreateDTO);
        if (success) {
            return new ResultVO(ResultVO.SUCCESS, "Comment published successfully", null);
        } else {
            return new ResultVO(ResultVO.FAIL, "Failed to publish comment", null);
        }
    }

    /**
     * 举报评论
     */
    @PutMapping("/api/comment/{commentId}/report")
    public ResultVO reportComment(@PathVariable("commentId") String commentId) {
        boolean success = postService.reportComment(commentId);
        if (success) {
            return new ResultVO(ResultVO.SUCCESS, "Comment reported successfully", null);
        } else {
            return new ResultVO(ResultVO.FAIL, "Failed to report comment or comment not found", null);
        }
    }

    /**
     * 举报帖子
     * 111
     */
    @PutMapping("/api/{imageId}/report")
    public ResultVO reportPost(@PathVariable("imageId") Long imageId) {
        boolean success = postService.reportPost(imageId);
        if (success) {
            return new ResultVO(ResultVO.SUCCESS, "Post reported successfully", null);
        } else {
            return new ResultVO(ResultVO.FAIL, "Failed to report post or post not found", null);
        }
    }
}
